/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.huangp.domain;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;

/**
 *
 * @author Patrick Huang
 */
@Entity
@Table(name="sms_transaction")
public class Transaction implements Serializable{
    //--------------------------------------------------------------------------
    // Static Properties
    //--------------------------------------------------------------------------
    /**
     * a constant that is used as key to store transaction id
     */
    public static final String TRANSACTION_ID = "transactionId";
    //--------------------------------------------------------------------------
    // Properties
    //--------------------------------------------------------------------------
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="tran_id")
    private Long id;

    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    @Column(name="request_time",updatable=false)
    private Date requestTime = new Date();

    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    @Column(name="response_time")
    private Date responseTime;

    @Column(length=255,updatable=false)
    private String request;

    @Column
    private Status status = Status.RUNNING;
    // -------------------------------------------------------------------------
    // Implementation Methods
    // -------------------------------------------------------------------------
    public Transaction(){
        super();
    }

    public Transaction(String request){
        super();
        this.request = request;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("Transaction:[");
        sb.append("id:[").append(id==null?"":id).append("],\n")
            .append("requestTime:[").append(requestTime).append("],\n")
            .append("responseTime:[").append(responseTime==null?"":responseTime).append("],\n")
            .append("status:[").append(status).append("],\n")
                ;
        return sb.toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Transaction other = (Transaction) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if (this.requestTime != null && other.requestTime != null && this.requestTime.compareTo(other.requestTime) != 0) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 59 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 59 * hash + (this.request != null ? this.request.hashCode() : 0);
        return hash;
    }

    // -------------------------------------------------------------------------
    // Mutator Methods
    // -------------------------------------------------------------------------
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getRequest() {
        return request;
    }

    public void setRequest(String request) {
        this.request = request;
    }

    public Date getRequestTime() {
        return requestTime;
    }

    public void setRequestTime(Date requestTime) {
        this.requestTime = requestTime;
    }

    public Date getResponseTime() {
        return responseTime;
    }

    public void setResponseTime(Date responseTime) {
        this.responseTime = responseTime;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }
}
